﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ABMath.IridiumExtensions;
using MathNet.Numerics.Distributions;
using MathNet.Numerics.LinearAlgebra;
using NUnit.Framework;

namespace ABMath.Tests.IridiumExtension
{
    [TestFixture]
    public class TDistributionExtensionsTest
    {
        #region Setup/Teardown

        [SetUp]
        public void SetUp()
        {
        }

        #endregion


        [Test]
        public void TestIt()
        {
            var v = new Vector(new[] {1.0,-1,1,-1,1,-1,5});
            var tdn = new StudentsTDistribution(5);
            double sig0 = Math.Sqrt(v.Variance())/Math.Sqrt(tdn.Variance);
            double sig1 = tdn.MLEofSigma(v);

            // now compare likelihood in two cases
            double ll0 = 0.0;
            double ll1 = 0.0;
            for (int i=0 ; i<v.Length ; ++i)
            {
                ll0 += Math.Log(tdn.ProbabilityDensity(v[i]/sig0)) - Math.Log(sig0);
                ll1 += Math.Log(tdn.ProbabilityDensity(v[i] / sig1)) - Math.Log(sig1);
            }
            Assert.Greater(ll1, ll0);
        }
    }
}
